package cn.tedu.basic;

import java.io.FileInputStream;
import java.io.InputStream;

//测试  JDK1.5的新特性
public class Test1_5 {
    public static void main(String[] args) {
       add(1,2);
       add(1,2,3);
       add(1,2,3,4);
       add(1,2,3,4,5,6);
    }

    private static void add(int ...a) {
        System.out.println(a.length);//a 本质上是一个数组
        //遍历a
        for (int x : a){
            System.out.print(x);
        }
    }
    //测试异常
public  class Test1_7 {
        public void main(String[] args) {
            Method();
            Method2();
        }

        public void Method() {
            InputStream inp = null;
            try {
                inp = new FileInputStream("D\\a");
                inp.read();
                inp.close();
            } catch (Exception a) {
                System.out.println("读取数据失败");
            } finally {
                try {
                    inp.close();
                } catch (Exception a) {
                    a.printStackTrace();
                }
            }
        }

        //IO自动关闭
        public void Method2() {
            try (InputStream in = new FileInputStream("D\\a");) {
                in.read();
                in.close();
            } catch (Exception a) {
                System.out.println("异常处理完毕");
            }
        }
    }
}
